import 'package:flutter/material.dart';
import 'package:flutter_taotaoshipin/widget/gaps.dart';
import 'package:flutter_taotaoshipin/widget/load_image.dart';

class DramaItem extends StatefulWidget {
  const DramaItem({
    super.key,
    required this.url,
    required this.name,
    this.tag = '',
    this.onTap,
  });

  final String url;
  final String name;
  final String tag;
  final Function()? onTap;

  @override
  State<DramaItem> createState() => _DramaItemState();
}

class _DramaItemState extends State<DramaItem> {
  @override
  Widget build(BuildContext context) {
    double width = (MediaQuery.of(context).size.width - 12 * 4) / 3;
    return InkWell(
      onTap: widget.onTap,
      child: Stack(
        children: [
          SizedBox(
            width: width,
            height: width * 1.7,
            child: Column(
              children: [
                Expanded(
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(10),
                    child: LoadImage(
                      widget.url,
                      width: width,
                    ),
                  ),
                ),
                Gaps.vGap5,
                Text(
                  widget.name,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
              ],
            ),
          ),
          // 标签
          if (widget.tag.isNotEmpty)
            Positioned(
              top: 5,
              right: 5,
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 4, vertical: 2),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(4),
                  gradient: LinearGradient(
                    colors: [
                      Colors.orange,
                      Colors.red,
                    ],
                  ),
                ),
                child: Text(
                  widget.tag,
                  style: TextStyle(
                    color: Colors.white70,
                    fontSize: 10,
                    fontWeight: FontWeight.w700,
                  ),
                ),
              ),
            ),
        ],
      ),
    );
  }
}
